$(function () {
  var app = {
    openId: GetRequest().openId,
    hostSever: getServerHost(),
    checkUser: '/api/longtaitou/checkUser',
    userFollow: false,
    startTime: false,
    threeTimes: 0,
    init: function () {
      this.ruler();
      this.judgeFollowAndStart();

    },
    ruler: function () {
      $('.rulerBtn').click(function () {
        $('.ruler').addClass('bounceIn').removeClass('bounceOut none');
        var myscroll = new iScroll("rulerSwapper", {
          onBeforeScrollStart: null,
          vScroll: true,
          vScrollbar: false,
          checkDOMChanges: true,
          hideScrollbar: true
        });
      });
      closeBar('.close', '.ruler');
    },
    judgeFollowAndStart: function () {
      // TODO: 判断是否关注
      $.get(app.hostSever + app.checkUser, {
        openId: app.openId
      }).done(
        function (rp) {
          if ('200' == rp.code) {
            app.userFollow = rp.res;
            app.linkToothers();
            $('.loading').hide();
          } else {

          }
        }
      ).fail(function () {

      })
    },
    linkToothers: function () {
      var context = this;
      $('.btn').on('click', router);

      function router() {
        //判断是否关注了公众号
        // TODO:
        if (!app.userFollow) {
          autoshowBar('.follow');
          return;
        }
        console.log($(this).index());
        var index = $(this).index();
        if (0 == Number(index)) {
          location.href = './collect.html?openId=' + app.openId;
        } else if (1 == Number(index)) {
          location.href = './exchange.html?openId=' + app.openId;
        } else if (2 == Number(index)) {
          console.log(app.clock, Number(app.startTime), Number(app.threeTimes));
          // TODO:  改
          location.href = './prize.html?openId=' + app.openId;
        }
      }
    }
  }
  app.init()
});